package com.atguigu.day26.day27morning.dbutils07;

import com.atguigu.day26.day27morning.m2dbtuils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;

/*
准备工作:
  1.导入jar
  2.添加依赖


增 删 改
 */
public class IDUTest {
    @Test
    public void test01() throws SQLException {
        //todo 增加
        //1.创建对象
        QueryRunner qr = new QueryRunner();
        //2.获取连接
        Connection connection = JDBCUtils.getConnection();
        //3.准备sql
        String sql = "insert into t_account values(null,?,?)";
        //4.执行操作
        qr.update(connection,sql,"安琪拉",5000);
        //5.关闭资源
        connection.close();
    }
    @Test
    public void test02() throws SQLException {
     //todo 删除
        //1.创建对象
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        //2.准备sql
        String sql = "delete from t_account where aname=?";
        //3.执行操作
        qr.update(sql,"赵丽颖");

    }

    @Test
    public void test03() throws SQLException {
     //todo 更新 aid 为5的数据 名字改为妲己 余额改为 6666

       // new QueryRunner(JDBCUtils.getDataSource()).update("update t_account set aname = ? ,balance = ? where aid = ?","妲己",6666,5);

        //1.创建对象
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        //2.准备sql
        String sql = "update t_account set aname = ? ,balance = ? where aid = ?";
        //3.执行操作
        qr.update(sql,"吕布",9999,5);


    }



}
